package com.bootdo.screen.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bootdo.screen.domain.HotwordtruenumDO;
import com.bootdo.screen.service.HotwordtruenumService;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;

/**
 * 
 * 
 * @author liyj
 * @email 1992lcg@163.com
 * @date 2018-11-06 11:29:10
 */
 
@Controller
@RequestMapping("/screen/hotwordtruenum")
public class HotwordtruenumController {
	@Autowired
	private HotwordtruenumService hotwordtruenumService;
	
	@GetMapping()
	//@RequiresPermissions("screen:hotwordtruenum:hotwordtruenum")
	String Hotwordtruenum(){
	    return "screen/hotwordtruenum/hotwordtruenum";
	}
	
	@ResponseBody
	@GetMapping("/list")
	//@RequiresPermissions("screen:hotwordtruenum:hotwordtruenum")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
		params.put("order","desc");
		params.put("sort","num");
        Query query = new Query(params);
		List<HotwordtruenumDO> hotwordtruenumList = hotwordtruenumService.list(query);
		int total = hotwordtruenumService.count(query);
		PageUtils pageUtils = new PageUtils(hotwordtruenumList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	//@RequiresPermissions("screen:hotwordtruenum:add")
	String add(){
	    return "screen/hotwordtruenum/add";
	}

	@GetMapping("/edit/{id}")
	//@RequiresPermissions("screen:hotwordtruenum:edit")
	String edit(@PathVariable("id") Integer id,Model model){
		HotwordtruenumDO hotwordtruenum = hotwordtruenumService.get(id);
		model.addAttribute("hotwordtruenum", hotwordtruenum);
	    return "screen/hotwordtruenum/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	//@RequiresPermissions("screen:hotwordtruenum:add")
	public R save( HotwordtruenumDO hotwordtruenum){
		if(hotwordtruenumService.save(hotwordtruenum)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	//@RequiresPermissions("screen:hotwordtruenum:edit")
	public R update( HotwordtruenumDO hotwordtruenum){
		hotwordtruenumService.update(hotwordtruenum);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	//@RequiresPermissions("screen:hotwordtruenum:remove")
	public R remove( Integer id){
		if(hotwordtruenumService.remove(id)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	//@RequiresPermissions("screen:hotwordtruenum:batchRemove")
	public R remove(@RequestParam("ids[]") Integer[] ids){
		hotwordtruenumService.batchRemove(ids);
		return R.ok();
	}
	
}
